#include <vector>
#include <iostream>
using namespace std;
class Solution
{
public:
    vector<int> productExceptSelf(vector<int> &nums)
    {
        int len = nums.size();
        vector<int> ans(len, 1);
        int n = 1,m = 1;
        for (int i = 0; i < len; i++)
        {
            ans[i] *= n;
            ans[len-1-i] *= m;
            n *= nums[i];
            m *= nums[len-1-i];
        }
        return ans;
    }
};
int main(int argc, char const *argv[])
{
    vector<int> v = {1, 2, 3, 4};
    Solution s;
    vector<int> ans = s.productExceptSelf(v);
    int len = ans.size();
    for (int i = 0; i < len; i++)
    {
        cout << ans[i] << ' ' ;
    }

    return 0;
}
